//
// Created by Crestimes on 24-5-10.
//

#ifndef TREENODE_H
#define TREENODE_H

#include <vector>

#include "Token.h"

typedef enum {
    PROGRAM,
    STMT_SEQUENCE,
    STATEMENT,
    AS_RG_STMT,
    REGEX_STMT,
    IF_STMT,
    REPEAT_STMT,
    ASSIGN_STMT,
    READ_STMT,
    WRITE_STMT,
    WHILE_STMT,
    FOR_STMT,

    EXP,
    EXP_LEVEL0,
    EXP_LEVEL1,
    EXP_LEVEL2,
    EXP_LEVEL3, // (EXP) 数字 变量
    EXP_LEVEL4, // ++ --

    REGEX, // '$' reg-level0 { '|' reg-level0 } '$'
    REG_LEVEL0, // &
    REG_LEVEL1, // # (*) ?
    REG_LEVEL2,
    REG_LEVEL3,
} BranchNodeType;


inline std::map<BranchNodeType, std::string> branchType2str = {
    {PROGRAM, "program"},
    {STMT_SEQUENCE, "stmt-sequence"},
    {STATEMENT, "statement"},
    {AS_RG_STMT, "as-rg-stmt"},
    {REGEX_STMT, "regex-stmt"},
    {IF_STMT, "if-stmt"},
    {REPEAT_STMT, "repeat-stmt"},
    {ASSIGN_STMT, "assign-stmt"},
    {READ_STMT, "read-stmt"},
    {WRITE_STMT, "write-stmt"},
    {WHILE_STMT, "while-stmt"},
    {FOR_STMT, "for-stmt"},

    {EXP, "exp"},
    {EXP_LEVEL0, "exp-level0"},
    {EXP_LEVEL1, "exp-level1"},
    {EXP_LEVEL2, "exp-level2"},
    {EXP_LEVEL3, "exp-level3"},
    {EXP_LEVEL4, "exp-level4"},

    {REGEX, "regex"},
    {REG_LEVEL0, "reg-level0"},
    {REG_LEVEL1, "reg-level1"},
    {REG_LEVEL2, "reg-level2"},
    {REG_LEVEL3, "reg-level3"},
};

typedef TokenType LeafNodeType;

class TreeNode {
public:
    BranchNodeType branch_type = PROGRAM;
    std::string leaf_str;
    std::vector<TreeNode*> children;
};


#endif //TREENODE_H
